
#pragma once

#include <QStandardItemModel>
#include <interactive_markers/interactive_marker_server.hpp>


using visualization_msgs::msg::InteractiveMarker;
using interactive_markers::InteractiveMarkerServer;


namespace rviz_custom_plugins
{


namespace viewmodels
{


class PointGroupModel : public QStandardItemModel
{
    Q_OBJECT

public:
    explicit PointGroupModel(QObject *parent = nullptr) ;

    inline static const QString L1_ROW = "l1_row";
    inline static const QString L2_ROW = "l2_row";

    Qt::ItemFlags flags(const QModelIndex& index) const override;

    bool appendGroup();
    void removeGroup(int l1Row);

    bool insertGroupItem(int l1Row, int l2Row, InteractiveMarker& intMarker);
    void removeGroupItem(int l1Row, int l2Row);

    InteractiveMarker& getGroupItem(int l1Row, int l2Row);
    std::list<InteractiveMarker>& getGroupItems(int l1Row);

    std::list<std::list<InteractiveMarker>>& getGroups();

    std::string& getGroupSign(int l1Row);

    void getMarkerRow(QString& markerName, int& l1Row, int& l2Row);
    void handleMarkerFeedback(InteractiveMarkerServer::FeedbackConstSharedPtr feedback);

    void setGroupTitlePrefix(QString prefix);

signals:
    void itemOrderUpdated(int l1Row, int l2Row, std::list<InteractiveMarker>& markers);

private:
    inline static int incrGroupSignId = 0;

    std::list<std::string> groupSigns;
    std::list<std::list<InteractiveMarker>> markersList;


    QString generateGroupSignName();

    void handleItemsReorder(int l1Row, int l2Row);
    void handleGroupsReorder(int l1Row);

    QString groupTitlePrefix;
    QString groupSignPrefix;



};


}


}
